package com.newtouch.cq.controllerlog.business.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newtouch.cq.controllerlog.business.entity.SysLog;
import com.newtouch.cq.controllerlog.business.mapper.SysLogMapper;
import com.newtouch.cq.controllerlog.business.model.dto.SysLogPageDto;
import com.newtouch.cq.controllerlog.business.service.ISysLogService;
import com.newtouch.cq.lang.result.MccPageResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统日志表 服务实现类
 * </p>
 *
 * @author Alex
 * @since 2021-09-03
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements ISysLogService {

    @Override
    public MccPageResult<SysLog> pageList(SysLogPageDto dto) {
        LambdaQueryWrapper<SysLog> wrapper = Wrappers.lambdaQuery(SysLog.class)
                .eq(StrUtil.isNotEmpty(dto.getCode()),SysLog::getCode,dto.getCode())
                .eq(StrUtil.isNotEmpty(dto.getRequestIp()), SysLog::getRequestIp,dto.getRequestIp())
                .like(StrUtil.isNotEmpty(dto.getUri()), SysLog::getUri, dto.getUri())
                .like(StrUtil.isNotEmpty(dto.getCreateName()), SysLog::getCreateName, dto.getCreateName());
        return MccPageResult.success(baseMapper.selectPage(dto.buildPage(),wrapper));
    }
}
